package me.zk.practice1.hw;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class HWBJ52 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int[] num = new int[4945];
        String[] strs = scanner.nextLine().split(",");

        for (int i = 0; i < strs.length; i++) {
            String s = strs[i];
            if (s.contains("-")) {
                int[] a = Arrays.stream(s.split("-")).mapToInt(Integer::parseInt).toArray();
                for (int j = a[0]; j <= a[1]; j++) {
                    num[j]=1;
                }

            } else {
                num[Integer.parseInt(s)]=1;
            }
        }
        String re = scanner.nextLine();
        num[Integer.parseInt(re)]=0;

        int index = 0;
        List<String> list = new ArrayList<>();
        while (index < num.length) {
            if (num[index] == 1) {
                StringBuffer sb = new StringBuffer();
                sb.append(index);
                int j = index;
                while (j < num.length && num[j]==1){
                    j++;
                }
                if (j-index !=1 ) {
                    sb.append("-");
                    sb.append(j-1);
                }
                list.add(sb.toString());
                index=j;
            } else {
                index++;
            }
        }
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < list.size(); i++) {
            sb.append(list.get(i));
            if (i != list.size()-1){
                sb.append(",");
            }
        }
        System.out.println(sb);
    }
}
